import { createSlice, } from '@reduxjs/toolkit';

interface FirstState {
  count: number;
  name: string;
  items: string[];
  isLoading: boolean;
}

const initialState: FirstState = {
  count: 0,
  name: 'First组件',
  items: ['项目1', '项目2', '项目3'],
  isLoading: false,
};

const firstSlice = createSlice({
  name: 'first',
  initialState,
  reducers: {
    increment: (state) => {
      state.count += 1;
    },
    decrement: (state) => {
      state.count -= 1;
    },
    incrementByAmount: (state, action) => {
      state.count += action.payload;
    },
    setName: (state, action) => {
      state.name = action.payload;
    },
    addItem: (state, action) => {
      state.items.push(action.payload);
    },
    removeItem: (state, action) => {
      state.items.splice(action.payload, 1);
    },
    setLoading: (state, action) => {
      state.isLoading = action.payload;
    },
    reset: (state) => {
      state.count = 0;
      state.name = 'First组件';
      state.items = ['项目1', '项目2', '项目3'];
      state.isLoading = false;
    },
  },
});

export const {
  increment,
  decrement,
  incrementByAmount,
  setName,
  addItem,
  removeItem,
  setLoading,
  reset,
} = firstSlice.actions;

export default firstSlice.reducer; 